package com.fanrui.code.chess.mahjong;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import com.fanrui.proto.cmd.HuType;
import com.fanrui.proto.cmd.MahjongBaseRoomConfig;
import com.fanrui.proto.cmd.MahjongType;

public class BaoHuRules extends MahjongRules {

	private static Map<HuType, Integer> huTypeCorrespondenceTable = new HashMap<HuType, Integer>();
	static {
		huTypeCorrespondenceTable.put(HuType.PINGHU, 1);
		huTypeCorrespondenceTable.put(HuType.DIANPAO, 0);
		huTypeCorrespondenceTable.put(HuType.ZIMo, 0);
		huTypeCorrespondenceTable.put(HuType.QIANGGANG, 0);
		huTypeCorrespondenceTable.put(HuType.ZIMo, 0);
		huTypeCorrespondenceTable.put(HuType.QIANGGANG, 0);
		huTypeCorrespondenceTable.put(HuType.HunYiSe, 0);
		huTypeCorrespondenceTable.put(HuType.SiGuiHu, 0);
	}
	
	private static Map<MahjongType, Integer> cards = new LinkedHashMap<MahjongType, Integer>();
	static {
		cards.put(MahjongType.TONG, 10);
		cards.put(MahjongType.TIAO, 10);
		cards.put(MahjongType.SAN, 8);
	}
	
	public BaoHuRules(MahjongBaseRoomConfig roomConfig) {
		super(roomConfig, cards, huTypeCorrespondenceTable);
		if(roomConfig.getBaoHuPlayStyle().getBaoHu() > 0) {
			huTypeCorrespondenceTable.put(HuType.BaoHu, 2 * roomConfig.getBaoHuPlayStyle().getBaoHu());
		}
		if(roomConfig.getBaoHuPlayStyle().getQiDui() > 0) {
			huTypeCorrespondenceTable.put(HuType.XIAOQIDUI, 4 * roomConfig.getBaoHuPlayStyle().getQiDui());
		}
		if(roomConfig.getBaoHuPlayStyle().getQingYiSe() > 0) {
			huTypeCorrespondenceTable.put(HuType.QingYiSe, 4 * roomConfig.getBaoHuPlayStyle().getQingYiSe());
		}
		if(roomConfig.getBaoHuPlayStyle().getHaoQiDui() > 0) {
			huTypeCorrespondenceTable.put(HuType.DAQIDUI, 4 * roomConfig.getBaoHuPlayStyle().getHaoQiDui());
		}
		if(roomConfig.getBaoHuPlayStyle().getQingSeBaoHu() > 0) {
			huTypeCorrespondenceTable.put(HuType.QingSeBaoHu, 4 * roomConfig.getBaoHuPlayStyle().getQingSeBaoHu());
		}
		if(roomConfig.getBaoHuPlayStyle().getZiYiSe() > 0) {
			huTypeCorrespondenceTable.put(HuType.ZiYiSe, 8 * roomConfig.getBaoHuPlayStyle().getZiYiSe());
		}
		if(roomConfig.getBaoHuPlayStyle().getGenZhuang()) {
			huTypeCorrespondenceTable.put(HuType.GenZhuangHu, 2);
		}
		if(roomConfig.getBaoHuPlayStyle().getGangBaoQuanBao()) {
			huTypeCorrespondenceTable.put(HuType.GangBaoQuanBao, 2);
		}
	}

	@Override
	public int maximumCapacity() {
		return roomConfig.getPlayerNumber();
	}

}
